package org.example.util.parser;

import lombok.extern.slf4j.Slf4j;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.example.vo.DocxVo;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Slf4j
public class ImageParser implements ParserInter {
    @Override
    public DocxVo parse(MultipartFile file) {
        ITesseract instance = new Tesseract();
        instance.setDatapath("C:\\software\\tessdata");
        instance.setLanguage("chi_sim"); // 设置识别语言为简体中文
        try {
            File tempFile = File.createTempFile("upload_", ".jpg");
            file.transferTo(tempFile);
            String result = instance.doOCR(tempFile);
            // 用完后删除
            tempFile.delete();
        } catch (TesseractException | IOException e) {
            log.error(e.getMessage());
        }

        return null;
    }
}
